package com.idata.model.proxyDO;

import cn.hutool.core.collection.ListUtil;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.idata.model.enums.CollaborativeCaseTypeEnum;
import com.idata.model.interfaces.CommonDisputeInfoCapacity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.math.NumberUtils;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @File CriminalCaseResponse.Java
 * @Modify Time      @Author    @Version    @Description
 * ------------      -------    --------    -----------
 * 2023/10/10         yd.j      1.0         None
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CollaborativeCaseDO extends KGBaseDisputeInfoDO implements CommonDisputeInfoCapacity {

    @JsonAlias("协同办案.当前强制措施")
    @JsonProperty
    private String currentCompulsoryMeasures;

    @JsonAlias("协同办案.简要案情")
    @JsonProperty
    private String briefCaseDescription;

    @JsonAlias("协同办案.违法信息")
    @JsonProperty
    private String illegalInformation;

    @JsonAlias("协同办案.接警时间")
    @JsonProperty
    private Date alarmTime;

    @JsonAlias("协同办案.人员涉案类别")
    @JsonProperty
    private String personnelInvolvedCategory;

    @JsonAlias("协同办案.META_CREATE_TIME")
    @JsonProperty
    private String metaCreateTime;

    @JsonAlias("协同办案.作案手段")
    @JsonProperty
    private String crimeMeans;

    @JsonAlias("协同办案.行政处罚决定")
    @JsonProperty
    private String administrativePenaltyDecision;

    @JsonAlias("协同办案.META_UPDATE_TIME")
    @JsonProperty
    private String metaUpdateTime;

    @JsonAlias("协同办案.额度")
    @JsonProperty
    private String amount;

    @JsonAlias("协同办案.作案因素")
    @JsonProperty
    private String crimeFactors;

    @JsonAlias("协同办案.起诉决定时间")
    @JsonProperty
    private Date prosecutionDecisionTime;

    @JsonAlias("协同办案.违法程度")
    @JsonProperty
    private String illegalDegree;

    @JsonAlias("协同办案.案发地点门楼牌号")
    @JsonProperty
    private String caseLocationBuildingNumber;

    @JsonAlias("协同办案.作案人数")
    @JsonProperty
    private int numberOfPerpetrators;

    @JsonAlias("协同办案.发案开始时间")
    @JsonProperty
    private Date crimeStartTime;

    @JsonAlias("协同办案.案由")
    @JsonProperty
    private String caseReason;

    @JsonAlias("协同办案.作案动机")
    @JsonProperty
    private String crimeMotivation;

    @JsonAlias("协同办案.作案特点")
    @JsonProperty
    private String crimeCharacteristics;

    @JsonAlias("协同办案.起诉罪名")
    @JsonProperty
    private String prosecutionCharge;

    @JsonAlias("协同办案.作案时机")
    @JsonProperty
    private String crimeTiming;

    @JsonAlias("协同办案.案发地点街路巷")
    @JsonProperty
    private String caseLocationStreet;

    @JsonAlias("协同办案.作案工具")
    @JsonProperty
    private String crimeTools;

    @JsonAlias("协同办案.处罚种类")
    @JsonProperty
    private String penaltyType;

    @JsonAlias("协同办案.案件状态")
    @JsonProperty
    private String caseStatus;

    @JsonAlias("协同办案.警情内容")
    @JsonProperty
    private String policeContent;

    @JsonAlias("协同办案.起诉书号")
    @JsonProperty
    private String indictmentNumber;

    @JsonAlias("协同办案.META_NAME")
    @JsonProperty
    private String metaName;

    @JsonAlias("协同办案.案件名称")
    @JsonProperty
    private String caseTitle;

//    // 基类中有案件编号，读取相同的json字段，这里映射不到
//    @JsonAlias("协同办案.案件编号")
//    @JsonProperty
//    private String caseNumber;

    @JsonAlias("协同办案.违法行为")
    @JsonProperty
    private String illegalAct;

    @JsonAlias("协同办案.违法处罚法律依据")
    @JsonProperty
    private String illegalPunishmentLegalBasis;

    @JsonAlias("协同办案.案件类型")
//    我需要ignore这个字段，所以不加 JsonProperty，否则就算在get方法上加上ignore，也会失效
    private String caseType;

    @JsonAlias("协同办案.发案区域")
    @JsonProperty
    private String caseRegion;

    @JsonAlias("协同办案.案发地点详细地址")
    @JsonProperty
    private String caseLocationDetails;

    @JsonAlias("协同办案.涉案罪名")
    @JsonProperty
    private String involvedCharge;

    @JsonAlias("协同办案.移送时间")
    @JsonProperty
    private Date transferTime;

    @JsonAlias("协同办案.违法处罚法律文件")
    @JsonProperty
    private String illegalPunishmentLegalFile;

    @JsonAlias("协同办案.法律法规依据")
    @JsonProperty
    private String legalBasis;

    @JsonIgnore
    public String getCaseType() {
        return caseType;
    }

    @Override
    public Date getDisputeTimeForSort() {
        return this.getCrimeStartTime() != null ?
                this.getCrimeStartTime() : this.getTransferTime();
    }

    @JsonIgnore
    @Override
    public List<String> getHotWordContext() {
        return ListUtil.toList(briefCaseDescription);
    }

    @Override
    public String getDisputeType() {
        return Optional.ofNullable(CollaborativeCaseTypeEnum.fromCode(NumberUtils.toInt(caseType)))
                .map(CollaborativeCaseTypeEnum::getDesc).orElse("");
    }

    @Override
    public String getDisputeContent() {
        return briefCaseDescription;
    }
}
